package com.njupt.utils;

import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.convention.ActionNameBuilder;

import com.opensymphony.xwork2.inject.Inject;

public class NjuptActionNameBuilder implements ActionNameBuilder
{
	private String actionSuffix = "Action";
	
	/**
     * @param   actionSuffix (Optional) Classes that end with these value will be mapped as actions
     *          (defaults to "Action")
     */
    @Inject(value = "struts.convention.action.suffix", required = false)
    public void setActionSuffix(String actionSuffix) {
        if (StringUtils.isNotBlank(actionSuffix)) {
            this.actionSuffix = actionSuffix;
        }
    }
	
	public String build(String className) {
		String actionName = className;

        // Truncate Action suffix if found
        if (actionName.endsWith(actionSuffix)) {
            actionName = actionName.substring(0, actionName.length() - actionSuffix.length());
        }
        if(actionName.length() > 1){
        	String first = actionName.substring(0, 1).toLowerCase();
    		actionName = first + actionName.substring(1,actionName.length());
        }else{
        	actionName = actionName.toLowerCase();
        }
		return actionName;
	}


}
